﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>呷饭网</title>
    <link rel="stylesheet" type="text/css" href="./styles/mobile.css" />
    <link href="styles/jquery.ui.all.css" rel="stylesheet" />
    <script type="text/javascript" src="scripts/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.bgiframe-2.1.1.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.core.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.widget.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.mouse.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.button.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.draggable.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.position.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.dialog.js"></script>
    <link href="styles/flexy-menu.css" rel="stylesheet" />
    <script type="text/javascript" src="scripts/flexy-menu.js"></script>
    <script type="text/javascript" src="scripts/common.js"></script>

    <script type="text/javascript">
        var OrderId;
        var Name;
        var HotelId;
        var BookedDate;
        var UrlFlag;
        var PageFlag;
        var array = new Array();

        $(function () {
            $(".flexy-menu").flexymenu({ speed: 100 });

            OrderId = getParameter("OrderId");
            Name = decodeURIComponent(getParameter("Name"));
            HotelId = getParameter("HotelId");
            $("#Dinecondition").text(Name);
            BookedDate = decodeURIComponent(getParameter("BookedDate"));
            $("#BookedDate").text(BookedDate);
            UrlFlag = getParameter("UrlFlag");
            PageFlag = getParameter("PageFlag");

            $('.goback').click(function () {
                if (PageFlag == "1") {
                    window.location.href = "./manager.html";
                }
                else if (PageFlag == "2") {
                    window.location.href = "./clean.html";
                }
                else if (PageFlag == "3") {
                    window.location.href = "./cashier.html";
                }
                else {
                    window.history.back();
                }
            });

            getUserInfo();
            getCookbookCategory();
        });

        //获取菜谱类别
        function getCookbookCategory() {
            $("#tblCookbook").html("");
            var url = "CommonPage.aspx?opration=getCookbookCategory";
            $.ajax({
                url: url,
                type: "post",
                dataType: 'json',
                success: function (data) {
                    if (data.Success) {
                        var str = "<tr>";
                        str += "<td id='ck_all'><a href=\"#\" onclick=\"getCookbookList('ck_all','');\">全部</a></td>";
                        for (var i = 0; i < data.List.length; i++) {
                            str += "<td id='ck_" + data.List[i].Id + "'><a href=\"#\" onclick=\"getCookbookList('ck_" + data.List[i].Id + "','" + data.List[i].Id + "');\">" + data.List[i].Name + "</a></td>";
                        }
                        str += "</tr>";
                        $("#tblCookbook").html(str);
                        getCookbookList("ck_all","");
                    }
                    else {
                        if (data.Url != "") {
                            updateTip(data.Msg, true, "URL", data.Url);
                        }
                        else {
                            updateTip(data.Msg, false, "", "");
                        }
                    }
                }
            });
        }

        //获取菜谱菜单
        function getCookbookList(id, flag) {
            $("#tblCookbook tr").find("td").each(function (a, b) {
                $("#" + b.id).removeClass("active");
                if (b.id == id) {
                    $("#" + id).addClass("active");
                }
            });

            $("input:text").each(function (a, b) {
                if (array.length != 0) {
                    for (var j = 0; j < array.length; j++) {
                        if (b.id == array[j].split(',')[0] && parseInt(b.value) != 0) {
                            array.splice(j, 1);
                        }
                    }
                }
                var str = b.id + "," + b.value;
                if (parseInt(b.value) != 0) {
                    array.push(str);
                }
            });

            $("#tblCookList").html("");
            var datas = "&flag=" + flag;
            var url = "CommonPage.aspx?opration=getCookbookList" + datas;
            $.ajax({
                url: url,
                type: "post",
                dataType: 'json',
                success: function (data) {
                    if (data.Success) {
                        $(".tips")[0].style.display = "none";
                        for (var i = 0, str = ''; i < data.List.length; i++) {
                            var EstimateClear = data.List[i].EstimateClear;
                            var tempstr = "";
                            if (EstimateClear == "-1") {
                                //tempstr = "<span>有<span>";
                            }
                            else if (EstimateClear == "0") {
                                tempstr = "<span>无<span>";
                            } else {
                                tempstr = "<span>剩余：" + EstimateClear + "份<span>";
                            }
                            /* str += "<tr><td class='l' style='padding-left:0;padding-right:0;width:100px;'>" + data.List[i].Name + "</td><td class='l' style='padding-left:0;padding-right:0;text-align:right;'>" + data.List[i].Price + "</td><td class='c' style='padding-left:0;padding-right:0;vertical-align:middle;text-align:center;'><img src='images/jian.png' onclick='subtractNum(" + data.List[i].CategoryId + "," + data.List[i].Id + "," + data.List[i].IsDisplay + ");'/><input type='text' id='ipt_" + data.List[i].CategoryId + "_" + data.List[i].Id + "_" + data.List[i].IsDisplay + "' readonly='readonly' value='0' style='width:20px;vertical-align:top;text-align:center;'/><img src='images/jia.png' onclick='addNum(" + data.List[i].CategoryId + "," + data.List[i].Id + "," + data.List[i].IsDisplay + "," + data.List[i].EstimateClear + ");'/></td><td class='r' style='padding-left:0;padding-right:0;text-align:right;'><a href='#' onclick='deleteCookbook(" + data.List[i].CategoryId + "," + data.List[i].Id + "," + data.List[i].IsDisplay + ");'>删除</a></td></tr>";*/
                            str += "<tr><td class='l' style='padding-left:0;padding-right:0;width:100px;'>" + data.List[i].Name + "</td><td class='l' style='padding-left:0;padding-right:0;text-align:right;'>" + data.List[i].Price + "</td><td class='c' style='padding-left:0;padding-right:0;vertical-align:middle;text-align:center;'><img src='images/jian.png' onclick='subtractNum(" + data.List[i].CategoryId + "," + data.List[i].Id + "," + data.List[i].IsDisplay + ");'/><input type='text' id='ipt_" + data.List[i].CategoryId + "_" + data.List[i].Id + "_" + data.List[i].IsDisplay + "' readonly='readonly' value='0' style='width:20px;vertical-align:top;text-align:center;'/><img src='images/jia.png' onclick='addNum(" + data.List[i].CategoryId + "," + data.List[i].Id + "," + data.List[i].IsDisplay + "," + data.List[i].EstimateClear + ");'/> " + tempstr + " </td><td class='r' style='padding-left:0;padding-right:0;text-align:right;'><a href='#' onclick='deleteCookbook(" + data.List[i].CategoryId + "," + data.List[i].Id + "," + data.List[i].IsDisplay + ");'>删除</a></td></tr>";
                        }
                        $("#tblCookList").html(str);

                        if (array.length != 0) {
                            for (var j = 0; j < array.length; j++) {
                                $("input:text").each(function (a, b) {
                                    if (array[j].split(',')[0] == b.id) {
                                        b.value = array[j].split(',')[1];
                                    }
                                });
                            }
                        }
                    }
                    else {
                        if (data.Url != "") {
                            updateTip(data.Msg, true, "URL", data.Url);
                        }
                        else {
                            $(".tips")[0].style.display = "";
                            $("#msgtip").text(data.Msg);
                        }
                    }
                }
            });
        }

        //提交菜单
        function updateOrderCookBook()
        {
            $("input:text").each(function (a, b) {
                if (array.length != 0) {
                    for (var j = 0; j < array.length; j++) {
                        if (b.id == array[j].split(',')[0] && parseInt(b.value) != 0) {
                            array.splice(j, 1);
                        }
                    }
                }
                var str = b.id + "," + b.value;
                if (parseInt(b.value) != 0) {
                    array.push(str);
                }
            });
            if (array.length == 0) {
                updateTip("请先点菜，再提交菜单！", false, "", "");
            }
            else {
                array = array.join('|');
                var datas = "&OrderId=" + OrderId + "&array=" + array + "&U_Id=-1&StateFlag=1";
                var url = "CommonPage.aspx?opration=updateOrderCookBook" + datas;
                $.ajax({
                    url: url,
                    type: "post",
                    dataType: 'json',
                    success: function (data) {
                        $(this).dialog("close");
                        if (data.Success) {
                            var str = data.Url + "?PageFlag=" + PageFlag + "&OrderId=" + OrderId;
                            //updateTip(data.Msg, true, "URL", str);
                            document.location.href = str;
                        }
                        else {
                            updateTip(data.Msg, false, "", "");
                        }
                    }
                });
            }
        }

        //取消此台
        function cancelDineTable()
        {
            $(".dialogTip").text("是否取消此台？")
            $("#dialog").dialog({
                resizable: false,
                height: 120,
                modal: true,
                position: ["center", "center"],
                buttons: {
                    "关 闭": function () {
                        $(this).dialog("close");
                    },
                    "确 定": function () {
                        var datas = "&HotelId=" + HotelId + "&OrderId=" + OrderId;
                        var url = "CommonPage.aspx?opration=cancelDineTable" + datas;
                        $.ajax({
                            url: url,
                            type: "post",
                            dataType: 'json',
                            success: function (data) {
                                $(this).dialog("close");
                                if (data.Success) {
                                    //updateTip(data.Msg, true, "URL", data.Url);
                                    //document.location.href = data.Url;
                                    document.location.href = UrlFlag;
                                }
                                else {
                                    updateTip(data.Msg, false, "", "");
                                }
                            }
                        });
                    }
                }
            });
        }
    </script>
</head>

<body>
    <div class="wrapall">
        <table class="topbar">
            <tr>
                <td class="l"><a class="goback">返回</a></td>
                <td class="c" id="H_Name"></td>
                <td class="r" >
                    <ul class="flexy-menu">
                        <li id="lilist">
                        </li>
                    </ul>
                </td>
            </tr>
        </table>
        <table class="tblhd">
            <tr>
                <td class="l" id="Dinecondition"></td>
                <td class="c"></td>
                <td class="r"></td>
            </tr>
        </table>
        <table class="tblbd">
            <tr>
                <th>就餐时间</th>
                <td id="BookedDate"></td>
            </tr>
        </table>
        <table class="tblbtn">
            <tr>
                <td class="l"><a href="#" onclick="updateOrderCookBook();">提交菜单</a></td>
                <td class="c"></td>
                <td class="r"><a href="#" onclick="cancelDineTable();">取消此台</a></td>
            </tr>
        </table>
        <table class="tab1" id="tblCookbook">
        </table>
        <table class="tbllist" id="tblCookList">
        </table>
        <span class="tips" id="tips" style="display:none;"><i></i><b id="msgtip"></b>
        </span>
        <br />
    </div>
    <div id="dialog" title="提示信息" style="text-align:center; vertical-align: middle;">
        <p class="dialogTip"></p>
    </div>
</body>
</html>